<?php
/**
 * @Notes: 文件描述
 * @Interface getCondition
 * @Return mixed
 * @Author: fc
 * @Time: 2021/4/19 15:28
 */

namespace app\common\command;

use mqtt\phpMQTT;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\facade\Hook;
use think\facade\Log;

class MqttSubscribe extends Command
{

    protected function configure()
    {
        $this->setName('mqtt:subscribe')->setDescription('物联网主题订阅');
    }

    protected function execute(Input $input, Output $output)
    {

        $server   = '111.230.25.120';
        $port     = 1883;
        $clientId = 'test-subscriber';

        $mqtt = new \PhpMqtt\Client\MqttClient($server, $port, $clientId);
        $mqtt->connect();

        $mqtt->subscribe('mytest', function ($topic, $message) {
            echo sprintf("Received message on topic [%s]: %s\n", $topic, $message);
        }, 0);

        $mqtt->loop(true);

        var_dump(13464);die;

        //$mqtt->disconnect();
    }


}